package org.example.TOOL;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;

import java.util.Collections;

/*
 * @author: farewell
 * @date: 2023/11/14
 * 实体类生成器工具代码
 */
public class Main {

    public static void main(String[] args) {
        // 数据库连接信息
        String dbUrl = "jdbc:mysql://10.10.1.8:3306/edubigdata?useUnicode=true&characterEncoding=utf-8&useSSL=false";
        String username = "edubigdata";
        String password = "4v&GUwYe@1Tr";

        // 需要生成的表名数组
     String[] tables1 = {"pd_cbjczl_xx", "pd_gccch_xx", "pd_gcctd_xx", "pd_jxsp_jxcgj_xx", "pd_jxsp_jyjxyjyggxm_xx", "pd_jxsp_pxjxqk_xx", "pd_jyhd_cjjskyqk_xx", "pd_kysp_fblwqk_xx", "pd_kysp_jskycgzhqk_xx", "pd_kysp_zlzz_xx", "pd_sxjd_jxxmjdqk_xx", "pd_sxjd_sxsjsxjdqk_xx", "pd_xxcx_czbyzp_xx", "pd_xxcx_fblwqk_xx", "pd_xxcx_jsqk_xx", "pd_xxcx_yszybs_xx", "pd_xxcx_zlzzq_xx", "pd_ylkcjs_xx", "pd_ysylzy_xx", "pd_jydh_cjcxcyxljh_xx", "pd_kysp_zckyxm_xx"};

        String[] tables = {"pd78_gccch"};
        // 遍历表名并生成实体类
        for (String table : tables) {
            FastAutoGenerator.create(dbUrl, username, password)
                    .globalConfig(builder -> {
                        builder.author("farewell") // 设置作者名
                                .outputDir(System.getProperty("user.dir") + "/src/main/java") // 输出目录
                                .disableOpenDir(); // 禁止打开输出目录
                    })
                    .packageConfig(builder -> {
                        builder.parent("org.example.score.domain.xiangxi") // 父包名
                                .pathInfo(Collections.singletonMap(OutputFile.valueOf("xml"), "")); // 禁用 Mapper XML 文件生成
                    })
                    .strategyConfig(builder -> {
                        builder.addInclude(table) // 当前表名
                                .entityBuilder()
                                .enableLombok() // 启用 Lombok
                                .formatFileName("%s"); // 实体类文件名格式
                    })
                    .templateConfig(builder -> {
                        builder.disable() // 禁用所有模板
                                .entity("/templates/entity.java"); // 仅启用实体类模板
                    })
                    .execute();
        }
    }
}